package com.developer.platform.application.command;

import cn.hutool.core.bean.BeanUtil;
import com.developer.platform.application.command.cmd.SystemAdd;
import com.developer.platform.application.command.cmd.SystemUpdate;
import com.developer.platform.domain.Systems;
import com.developer.platform.domain.service.ISystemService;
import com.developer.platform.infrastructure.data.mapper.SystemMapper;
import org.springframework.stereotype.Component;

/**
 * @author ：qiaoliang
 * @date ：2020-12-29
 */
@Component
public class SystemCmdManager {

  private final SystemMapper systemMapper;
  private final ISystemService systemService;

  public SystemCmdManager(
      SystemMapper systemMapper,
      ISystemService systemService) {
    this.systemMapper = systemMapper;
    this.systemService = systemService;
  }

  public void save(SystemAdd systemAdd){
    Systems systems = new Systems();
    BeanUtil.copyProperties(systemAdd, systems);
    systemMapper.insert(systems);
  }

  public void update(long id, SystemUpdate systemUpdate){
    Systems systems = new Systems(id);
    BeanUtil.copyProperties(systemUpdate, systems);
    systemMapper.updateById(systems);
  }

  public void delete(long id){
    systemService.deleteById(id);
  }
}
